/*
*    Reversi Contender homepage:  http://code.google.com/p/reversi-contender
*
*    copyright 2011 steven sims <steven.joseph.sims at gmail.com>
*
*    This file is part of Reversi Contender.
*
*    Reversi Contender is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Reversi Contender is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with Reversi Contender.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.threadswarm.reversi.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author steve
 */
public class AboutActionListener implements ActionListener {

    private final JFrame frame;
    private JDialog dialog = null;

    public AboutActionListener(JFrame frame) {
        this.frame = frame;
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        if(dialog == null){
            dialog = new JDialog(frame, "About Reversi Contender", true);
            dialog.setResizable(false);
            JPanel contentPanel = (JPanel) dialog.getContentPane();
            contentPanel.setPreferredSize(new Dimension(311, 254));
            contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
            
            contentPanel.add(Box.createRigidArea(new Dimension(0, 5)));
            ImageIcon logoIcon = new ImageIcon((Thread.currentThread().getContextClassLoader().getResource("images/logo.png")));
            JLabel logoLabel = new JLabel(logoIcon);
            logoLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
            contentPanel.add(logoLabel);

            contentPanel.add(Box.createRigidArea(new Dimension(0, 5)));
            JLabel titleLabel = new JLabel("Reversi Contender");
            titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
            titleLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
            contentPanel.add(titleLabel);

            contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
            JLabel descLabel = new JLabel("A Reversi implementation for the JVM");
            descLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
            descLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
            contentPanel.add(descLabel);

            contentPanel.add(Box.createRigidArea(new Dimension(0, 25)));
            JLabel creditLabel = new JLabel("Designed and coded by Steven Sims");
            creditLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
            creditLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
            contentPanel.add(creditLabel);

            contentPanel.add(Box.createRigidArea(new Dimension(0, 30)));
            JButton closeButton = new JButton("Close");
            closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
            closeButton.addActionListener(new CloseButtonActionListener(dialog));
            contentPanel.add(closeButton);

            dialog.pack();
        }

        dialog.setLocationRelativeTo(frame);
        dialog.setVisible(true);
    }

    private static class CloseButtonActionListener implements ActionListener {

        private final JDialog dialog;

        public CloseButtonActionListener(JDialog dialog) {
            this.dialog = dialog;
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            dialog.setVisible(false);
        }

    }

}
